package com.pes.arcww.form;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name="TOPICS")
public class Topics implements Comparable<Topics>, Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "TOP_ID", unique = true)
	@GeneratedValue
	private Integer top_id;
	
	@Column(name = "TOP_TITLE", length = 45)
	private String title;
	
	@Column(name = "TOP_DESCRIPTION", length = 255)
	private String description;
	
	@OneToMany(mappedBy = "topic", orphanRemoval = true)
	private Collection<Questions> questionsList = new ArrayList<Questions>();
	
	@ManyToMany
	@JoinTable(name="CNT_TOPICS", joinColumns={@JoinColumn(name="top_id_fk")}, 
	inverseJoinColumns={@JoinColumn(name="pro_id_fk")})
	@LazyCollection(LazyCollectionOption.FALSE)
	private Collection<Profiles> profilesList = new ArrayList<Profiles>();

	public Integer getId() {
		return top_id;
	}

	public void setId(Integer top_id) {
		this.top_id = top_id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Collection<Questions> getQuestionsList() {
		return questionsList;
	}

	public void setQuestionsList(Collection<Questions> questionsList) {
		this.questionsList = questionsList;
	}

	public Collection<Profiles> getProfilesList() {
		return profilesList;
	}

	public void setProfilesList(Collection<Profiles> profilesList) {
		this.profilesList = profilesList;
	}

	@Override
	public boolean equals(Object obj) {		
		return ( ((Topics)obj).getId()== this.getId());
	}
	
	public int compareTo(Topics o) {
		return  (o == this)? 0 : 1;
	}
	
	
}
